package mall.repository;

import mall.entity.OrderItem;

import java.sql.ResultSet;
import java.util.List;

public class OrderItemDao extends BaseDao<OrderItem> {


    @Override
    public OrderItem rowToObject(ResultSet rs) throws Exception {
        OrderItem orderItem = new OrderItem();
        orderItem.setId(rs.getInt("id"));
        orderItem.setOrderNumber(rs.getString("order_number"));
        orderItem.setProductId(rs.getInt("product_id"));
        orderItem.setQuantity(rs.getInt("quantity"));
        orderItem.setPrice(rs.getBigDecimal("price"));
        return orderItem;
    }


    public int insert(OrderItem orderItem){
        String sql = "insert into order_item(order_number, product_id, quantity, price) values(?, ?, ?, ?)";
        return executeUpdate(sql, orderItem.getOrderNumber(), orderItem.getProductId(), orderItem.getQuantity(), orderItem.getPrice());
    }


    public List<OrderItem> selectListByOrderNumber(String orderNumber) {
        return executeQuery("select * from  `order_item` where order_number = ? ", orderNumber);
    }
}
